BGE嵌入模型API使用说明

接口信息

  • 接口地址: https://openai/v1/embeddings
  • 请求方法: POST
  • Content-Type: application/json

认证方式

Authorization Bearer

在请求头 (Header) 中加入 Authorization 字段进行认证。

Authorization: Bearer YOUR_API_KEY

请求参数

必填参数

参数名 类型 说明
input Array[String] 待处理的文本列表

可选参数

参数名 类型 默认值 说明
max_length Integer 512 文本最大长度

响应格式

{
  "embeddings": [
    [0.123, -0.456, 0.789, ...],
    [0.234, -0.567, 0.891, ...]
  ],
  "processing_time": 0.1234,
  "input_count": 2
}
字段名 类型 说明
embeddings Array[Array[Float]] 文本嵌入向量列表
processing_time Float 处理时间 (秒)
input_count Integer 处理的文本数量

使用示例

基础用法

curl -X POST "https://openai/v1/embeddings" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": ["这是一个测试文本", "This is a test text"]
  }'

指定文本长度

curl -X POST "https://openai/v1/embeddings" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": [
      "深度学习是机器学习的一个分支"
    ],
    "max_length": 256
  }'

批量处理

curl -X POST "https://apiai.sztu.edu.cn/v1/models/embeddings" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": [
      "文本1: 产品介绍和功能说明",
      "文本2: 用户评价和反馈信息",
      "文本3: Technical documentation",
      "文本4: 市场分析和研究报告",
      "文本5: Customer support guide"
    ]
  }'

错误处理

HTTP状态码 说明 解决方案
400 请求参数错误 检查请求格式
401 API密钥无效 检查密钥是否正确

注意事项

  • 请妥善保管API密钥,不要在客户端代码中暴露。
  • 建议批量处理多个文本以提高效率。